import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/login.vue'
import Home from '../components/home.vue'
import ManageTag from '../components/tag/ManageTag.vue'
import ManageType from '../components/type/ManageType.vue'
import ManageBlog from '../components/article/ManageBlog.vue'
import ManageEssay from '../components/article/ManageEssay.vue'
import ManageMessage from '../components/message/ManageMessage.vue'
import ManageComment from '../components/message/ManageComment.vue'
import ManageUser from '../components/user/ManageUser.vue'
import Publish from '../components/article/Publish.vue'
import Welcome from '../components/welcome.vue'
import EditBlog from '../components/article/EditBlog.vue'
import ManageAuthorInfo from '../components/system/ManageAuthorInfo.vue'
import ManageFriendSite from '../components/system/FriendSite.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      { path: '/managetag', component: ManageTag },
      { path: '/managetype', component: ManageType },
      { path: '/manageblog', component: ManageBlog },
      { path: '/manageessay', component: ManageEssay },
      { path: '/managemessage', component: ManageMessage },
      { path: '/managecomment', component: ManageComment },
      { path: '/manageuser', component: ManageUser },
      { path: '/manageauthor', component: ManageAuthorInfo },
      { path: '/site', component: ManageFriendSite },
      { path: '/publish', component: Publish },
      { path: '/welcome', component: Welcome },
      { path: '/edit/:id', component: EditBlog }
    ]
  }
]

const router = new VueRouter({
  base: '/management/',
  routes,
  mode: 'history'
})

// router.beforeEach((to, from, next) => {
// // to将要访问的路径
// // from代表从哪个路径跳转过来
// // next是一个函数，表示放行
// // next()放行，next('/login')强制跳转
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenstr = window.sessionStorage.getItem('token')
//   if (!tokenstr) return next('/login')
//   next()
// })

export default router
